home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2006 May / PCWMAY06.iso / Software / Freeware / First Page 2006 3.00 / fp2006-final-3.00-setup.exe / {app} / Iscripts / Forms Misc / zip-code-val.izs < prev    next >
Text File  |  2005-09-28  |  3KB  |  131 lines

  1. <!NOWIZARD>
  2.  
  3. <!TITLE>Zip Code Validation 
  4. <!/TITLE>
  5.  
  6. <!DESCRIPTION>Ensure that your visitors enter a properly formatted 5 digit, or 5 digit+4 zip code. The visitor is alerted if any information is invalid and asked to try again.  <!/DESCRIPTION> 
  7.  
  8. <!CATEGORY>Forms<!/CATEGORY>
  9.  
  10. <!SCRIPT>
  11. <!-- START OF SCRIPT -->
  12.  
  13.  
  14. <!-- HOW TO INSTALL ZIP CODE VALIDATION:
  15.  
  16.   1.  Copy code into the HEAD section of document
  17.   2.  Put last coding into the BODY section of document  -->
  18.  
  19. <!-- STEP ONE: Add code into HEAD section of document  -->
  20.  
  21. <HEAD>
  22.  
  23. <SCRIPT LANGUAGE="JavaScript">
  24. <!-- Original:  Brian Swalwell -->
  25.  
  26.  
  27.  
  28. <!-- Begin
  29. function validateZIP(field) {
  30. var valid = "0123456789-";
  31. var hyphencount = 0;
  32.  
  33. if (field.length!=5 && field.length!=10) {
  34. alert("Please enter your 5 digit or 5 digit+4 zip code.");
  35. return false;
  36. }
  37. for (var i=0; i < field.length; i++) {
  38. temp = "" + field.substring(i, i+1);
  39. if (temp == "-") hyphencount++;
  40. if (valid.indexOf(temp) == "-1") {
  41. alert("Invalid characters in your zip code.  Please try again.");
  42. return false;
  43. }
  44. if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-")) {
  45. alert("The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'.   Please try again.");
  46. return false;
  47.    }
  48. }
  49. return true;
  50. }
  51. //  End -->
  52. </script>
  53. </HEAD>
  54.  
  55. <!-- STEP TWO: Add code into BODY section of document  -->
  56.  
  57. <BODY>
  58.  
  59. <center>
  60. <form name=zip onSubmit="return validateZIP(this.zip.value)">
  61. Zip: <input type=text size=30 name=zip>
  62. <input type=submit value="Submit">
  63. </form>
  64. </center>
  65.  
  66.  
  67. <!-- END OF SCRIPT -->
  68. <!/SCRIPT>
  69.  
  70. <!PREVIEW>
  71. <!-- START OF SCRIPT -->
  72.  
  73.  
  74. <!-- HOW TO INSTALL ZIP CODE VALIDATION:
  75.  
  76.   1.  Copy code into the HEAD section of document
  77.   2.  Put last coding into the BODY section of document  -->
  78.  
  79. <!-- STEP ONE: Add code into HEAD section of document  -->
  80.  
  81. <HEAD>
  82.  
  83. <SCRIPT LANGUAGE="JavaScript">
  84. <!-- Original:  Brian Swalwell -->
  85.  
  86.  
  87.  
  88. <!-- Begin
  89. function validateZIP(field) {
  90. var valid = "0123456789-";
  91. var hyphencount = 0;
  92.  
  93. if (field.length!=5 && field.length!=10) {
  94. alert("Please enter your 5 digit or 5 digit+4 zip code.");
  95. return false;
  96. }
  97. for (var i=0; i < field.length; i++) {
  98. temp = "" + field.substring(i, i+1);
  99. if (temp == "-") hyphencount++;
  100. if (valid.indexOf(temp) == "-1") {
  101. alert("Invalid characters in your zip code.  Please try again.");
  102. return false;
  103. }
  104. if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-")) {
  105. alert("The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'.   Please try again.");
  106. return false;
  107.    }
  108. }
  109. return true;
  110. }
  111. //  End -->
  112. </script>
  113. </HEAD>
  114.  
  115. <!-- STEP TWO: Add code into BODY section of document  -->
  116.  
  117. <BODY>
  118.  
  119. <center>
  120. <form name=zip onSubmit="return validateZIP(this.zip.value)">
  121. Zip: <input type=text size=30 name=zip>
  122. <input type=submit value="Submit">
  123. </form>
  124. </center>
  125.  
  126.  
  127. <!-- END OF SCRIPT -->
  128. <!/PREVIEW>
  129.  
  130. <!RELATED>NONE<!/RELATED>
  131.